package com.henry.chatkit.conversation

import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class ConversationLayout : RecyclerView {

    val mAdapter: ConversationListAdapter by lazy { ConversationListAdapter() }

    constructor(context: Context) : super(context) {
        initView()
    }
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView()
    }
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initView()
    }

    private fun initView() {
        val linearLayoutManager = LinearLayoutManager(context)
        linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
        layoutManager = linearLayoutManager
        adapter = mAdapter
    }

    fun getData(): List<ConversationInfo> {
        return mAdapter.getData()
    }

    fun reloadData(list: List<ConversationInfo>) {
        mAdapter.reloadData(list)
    }

    fun addConversations(list: List<ConversationInfo>) {
        mAdapter.addItems(list)
    }

    fun addConversation(position: Int, info: ConversationInfo?) {
        mAdapter.addItem(position, info)
    }

    fun removeConversation(position: Int) {
        mAdapter.removeItem(position)
    }

}